package cn.itcast.mq.email.listener;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;

import java.io.IOException;
import java.util.Map;

public class EmailListener implements MessageListener {

    @Override
    public void onMessage(Message message) {
        byte[] body = message.getBody();
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            Map<String,String> map = objectMapper.readValue(body, Map.class);
            String to = map.get("to");
            String title = map.get("title");
            String content = map.get("content");
            System.out.println("发送邮件："+to);
           //  MailUtil.sendMail(to, title, content);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
